package com.ljh;


import com.ljh.bean.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class AnnotationConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        final ConsumerComponent service = context.getBean(ConsumerComponent.class);

        //创建1分钟能调用2000次方法的线程池
        LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue();
        Executor executor = new ThreadPoolExecutor(1, 20, 2000L, TimeUnit.MILLISECONDS, linkedBlockingQueue);

        int totalReq=2100;
        System.out.println("请求一共："+totalReq);
        int index=0;
        while (index<2100) {

            index++;

            executor.execute(new Runnable() {
                public void run() {
                    service.getUserA("User A");
                }
            });

            executor.execute(new Runnable() {
                public void run() {
                    service.getUserB("User B");
                }
            });

            executor.execute(new Runnable() {
                public void run() {
                    service.getUserC("User C");
                }
            });
        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("com.ljh.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
